package com.jiu345.users.controller;

import com.jiu345.users.pojo.Address;
import com.jiu345.users.pojo.Member;
import com.jiu345.users.pojo.bo.AuthBo;
import com.jiu345.users.pojo.vo.AuthVo;
import com.jiu345.users.pojo.vo.MemberVo;
import com.jiu345.users.service.IAuthService;
import com.jiu345.users.service.IUserService;
import jakarta.validation.constraints.NotNull;
import lombok.RequiredArgsConstructor;
import org.dromara.common.core.domain.R;
import org.dromara.common.core.validate.EditGroup;
import org.dromara.common.web.core.BaseController;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * package:AuthController
 *
 * @author MrLei QQ:235921049
 * desc:用户登录
 * @Date 2024.07.05 15:13
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/api/user/info")
public class UserController extends BaseController {
    private final IUserService userService;

    /*用户信息*/
    @GetMapping("/{id}")
    public R<MemberVo> userInfo(@NotNull(message = "主键不能为空")
                              @PathVariable Long id) {
        return R.ok(userService.userInfo(id));
    }
    /*修改用户信息*/
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody Member bo) {
        return toAjax(userService.updateByBo(bo));
    }

    /*修改头像*/
    @PostMapping("/{id}/{avatar}")
    public R<Void> updateAvatar(@NotNull(message = "主键不能为空")
                                @PathVariable Long id,
                                @PathVariable String avatar) {
        return toAjax(userService.updateAvatar(id,avatar,true));
    }
//    @PostMapping("/avatar")
//    public R<Void> updateAvatar(@Validated(EditGroup.class) @RequestBody Member bo) {
//        return toAjax(userService.updateAvatar(bo));
//    }

}
